"""
Author : Tim Tucker
"""

import wx

from LMG.Utility.constants import * # pylint: disable-msg = W0611,W0401


################################################################

class DupFileDialog(wx.Dialog):
    """
    Asks whether or not to overwrite files

    Will return one several values:
    -2: No to All
    -1: No
     1: Yes
     2: Yes to All
    """
    def __init__(self, torrent, filename, single = True):                
        wx.Dialog.__init__(self, None, -1, _('Duplicate file name'))

        message = "Torrent : "+ torrent.getColumnText(COL_TITLE) + "\n" + \
                  "File : " + filename + "\n" +\
                  _('A file with the same name already exists in the destination folder.\nDo you want to overwrite it?')

        outerbox = wx.BoxSizer( wx.VERTICAL )

        outerbox.Add(wx.StaticText(self, -1, message), 0, wx.ALIGN_LEFT|wx.ALL, 5)
               
        self.yesbtn = wx.Button(self, wx.ID_YES, _('Yes'))
        self.Bind(wx.EVT_BUTTON, self._onYES, self.yesbtn)

        self.yestoallbtn = wx.Button(self, wx.ID_YESTOALL, _('Yes to all'))
        self.Bind(wx.EVT_BUTTON, self._onYESTOALL, self.yestoallbtn)
        
        self.nobtn = wx.Button(self, wx.ID_NO, _('No'))
        self.Bind(wx.EVT_BUTTON, self._onNO, self.nobtn)

        self.notoallbtn = wx.Button(self, wx.ID_NOTOALL, _('No to all'))
        self.Bind(wx.EVT_BUTTON, self._onNOTOALL, self.notoallbtn)

        buttonbox = wx.BoxSizer( wx.HORIZONTAL )
        buttonbox.Add(self.yesbtn, 0, wx.ALL, 5)
        buttonbox.Add(self.yestoallbtn, 0, wx.ALL, 5)
        buttonbox.Add(self.nobtn, 0, wx.ALL, 5)
        buttonbox.Add(self.notoallbtn, 0, wx.ALL, 5)

        outerbox.Add( buttonbox, 0, wx.ALIGN_CENTER)

        self.SetAutoLayout(True)
        self.SetSizerAndFit(outerbox)
        
    def _onYES(self, event = None):
        self.EndModal(1)

    def _onYESTOALL(self, event = None):
        self.EndModal(2)

    def _onNO(self, event = None):
        self.EndModal(-1)
        
    def _onNOTOALL(self, event = None):
        self.EndModal(-2)
